package com.tech.arno.spicysdk;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;

import java.io.IOException;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

/**
 * Created by Arno on 2017/12/7 0007.
 */

public class BaseOkhttpTestActivity extends AppCompatActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        sendRequest();
//        test();
    }
    /*
    * 用Okhttp发送一个最基本网络请求
    */

    private void sendRequest() {
        OkHttpClient mOkhttpClient = new OkHttpClient();
        //创建一个 Request
        final Request request = new Request.Builder()
                .url("https://www.imooc.com/")
                .build();
        //new Call
        Call call = mOkhttpClient.newCall(request);
        //请求加入调度
        call.enqueue(new Callback() {

            @Override
            public void onFailure(Call call, IOException e) {

            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {

            }
        });
    }

//    private void test() {
//        CommonOkHttpClient.sendRequest(CommonRequest
//                        .createGetRequest("http://www.imooc.com", null),
//                new CommonJsonCallback(new DisposeDataHandle(new DisposeDataListener() {
//                    @Override
//                    public void onSuccess(Object responseObj) {
//
//                    }
//
//                    @Override
//                    public void onFailure(Object reasonObj) {
//
//                    }
//                })));
//    }
}
